﻿var isShow = true;
var timerId = null;
var colsNum = 190;
var menu = document.getElementById("navTd");
var parentWindow = window.parent;
var muneFrame = parentWindow.document.getElementById('muneFrame');
var leftFrame = parentWindow.document.getElementById('leftFrame');
var aFrame = parentWindow.document.getElementById('aFrame');

// 设置框架大小
function setClos() {
    if (leftFrame != null && muneFrame != null && leftFrame != undefined && muneFrame != undefined) {
        leftFrame.cols = (200 - colsNum) + ",*";
        muneFrame.cols = colsNum + ",*";

        if (menu != null && menu != undefined) {
            menu.style.opacity = colsNum / 200;
            menu.style.filter = "alpha(opacity=" + colsNum / 10 + ")";
        }
        if (isShow) {
            colsNum -= 18;
        }
        else {
            colsNum += 18;
        }
    }
}

// 递归函数，改变框架大小
function ShowNavBar(fun) {
    if (colsNum > 190 || colsNum < 10) {
        if (isShow) {
            muneFrame.cols = "10,*";
            leftFrame.cols = "190,*";
            if (menu != null && menu != undefined) {
                menu.style.display = "none";
            }

        }
        else {
            $("leftMenu").css("left_nav_bg");
            muneFrame.cols = "190,*";
            leftFrame.cols = "10,*";
            if (menu != null && menu != undefined) {
                menu.style.display = "block";
            }
        }
        isShow = !isShow;
        mouseover();
        fun;
        return;
    }
    else {
        setClos();
        timerId = setTimeout("ShowNavBar()", 10);
    }
}

// 强制隐藏
function closeLeft() {
    isShow = true;
    if (menu != null && menu != undefined)
        ShowNavBar(function() {
            muneFrame.cols = "200,*";
            leftFrame.cols = "0,*";
            leftFrame.style.display = "none";
            if (menu != null && menu != undefined) {
                menu.style.display = "none";
            }
        });
};


// 绑定事件
var leftcloseBtn = document.getElementById("leftClose");
if (leftcloseBtn != null && leftcloseBtn != undefined) {
    leftcloseBtn.onclick = function() {
        if (isShow) {
            menu.style.opacity = 0;
            menu.style.filter = "alpha(opacity=0)";
            colsNum = 190;
        }
        else {
            menu.style.display = "block";
            menu.style.opacity = 1;
            menu.style.filter = "alpha(opacity=100)";
            colsNum = 10;
        }
        ShowNavBar();
    }

    leftcloseBtn.onmouseover = function() {
        var img = document.getElementById("imgLeft");
        if (isShow) {
            img.src = pagesrc + "/left_hover.gif";
        }
        else {
            img.src = pagesrc + "/right_hover.gif";
        }
    }

    leftcloseBtn.onmouseout = mouseover;
};

function mouseover() {
    var img = document.getElementById("imgLeft");
    if (isShow) {
        img.src = pagesrc + "/left.gif";
    }
    else {
        img.src = pagesrc + "/right.gif";
    }
};

// 页面加载后的操作
function onloadFun(hidediv, me, name) {
    isShow = true;
    menu.style.display = "block";
    leftFrame.style.display = "block";
    
    //鼠标移动到上面时触发的样式设置
    //select 之后的样式还是没有解决
	$(".node").bind("mouseover",function(){$(this).css("background","url(/finance/risk/test/left_menu_text_select.jpg) no-repeat");})
	$(".node").bind("mouseout",function(){$(this).css("background","url(/finance/risk/test/left_menu_text_li.gif) no-repeat left");})
//	$(".node").bind("mouseover",function(){$(this).addClass("left_menu_text"); });//  css("background","#9F79EE");})
//	$(".node").bind("mouseout",function(){$(this).addClass("left_menu_text");});//css("background","white");})

    $(".left_menu_head").children(".left_menu_icon1").next().removeClass("icon_adown");
    $(".left_menu_head").children(".left_menu_icon1").next().addClass("icon_up");

    var nowSel = document.getElementById(name);
    if (nowSel != null) {
        nowSel.attributes['class'].value = "select";
    }

    $("#" + me).removeClass("icon_adown");
    $("#" + me).addClass("icon_up");

    $("#" + hidediv).css({ "display": 'none' })
    divhide(hidediv, me, SelectMenu(name));
};


// 显示，隐藏
function divhide(hidediv, me, over) {
    if (hidediv == undefined || hidediv == null) {
        return;
    }

    var _a = $(".left_menu_text");
    $.each(_a, function(i, n) {
        $(n).hide('middle');
    })

    if ($("#" + hidediv).css("display") == "block") {
        $("#" + hidediv).hide("middle");

        $("#" + me).removeClass("icon_adown");
        $("#" + me).addClass("icon_up");
    }
    else {
        $("#" + hidediv).show("middle", over);
        $("#" + me).removeClass("icon_up");
        $("#" + me).addClass("icon_adown");
    }



    over;
};

// 选中
if (perSelect == null || perSelect == undefined) {
    var perSelect = "abc";
};

function SelectMenu(nowSelect) {
    var preSel = document.getElementById(perSelect);
    var nowSel = document.getElementById(nowSelect);
    if (preSel != null) {
        preSel.attributes['class'].value = "";
    }
    if (nowSel != null) {
        perSelect = nowSelect;
        nowSel.attributes['class'].value = "select";
    }
};